products = [["iphone", 6888], ["MacPro", 14800], [
    "小米6", 2499], ["Coffee", 31], ["Book", 60], ["Nike", 699]]


# 展示所有商品列表信息
def show_products():
    """
     展示商品列表
    """
    print("------ 商品列表 ------")
    print("序号    商品名称     商品价格")
    for j in range(0, len(products)):
        print('{}\t\t{}\t\t{}'.format(str(j), products[j][0], products[j][1]))


# 打印选择商品信息，购物车
def choice_products():
    """
    打印选择商品信息，类似购物车
    """
    id_list = [str(i) for i in range(0, len(products))]
    shop_car = []
    # print(id_list)
    while True:
        print("")
        i = input("请输入选择的商品序号(输入q退出,输入m清空购物车)：")
        if i == "m":
            shop_car.clear()
            print("购物车清空成功")
        elif i == "q":
            print("------ 购物车列表 ------")
            print("序号    商品名称     商品价格")
            # print(shop_car)
            for j in range(0, len(shop_car)):
                print('{}\t\t{}\t\t{}'.format(
                    shop_car[j][0], shop_car[j][1], shop_car[j][2]))

            break
        elif i not in id_list:
            print("输入的商品序号有误,请检查重新输入！")
            continue
        else:
            i = int(i)
            add_list = []
            add_list.extend([str(i), products[i][0], products[i][1]])
            shop_car.append(add_list)
            print('{}加入购物车'.format(products[i][0]))
            # print('添加的商品为：{}\t\t{}\t\t{}'.format(i, products[i][0], products[i][1]))


if __name__ == '__main__':
    show_products()
    choice_products()
# 完成的不错
